package utils.document;

import java.io.FileInputStream;
import java.io.IOException;

import static utils.document.Doc2HtmlUtil.getDoc2HtmlUtilInstance;

public class OfficeToPdf {

    public OfficeToPdf() {
        //openoffice开启服务
        String OpenOfficeHome = "D:/OpenOffice/install/program/";
        String command = OpenOfficeHome + "soffice -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard\n";
        try {
            Runtime.getRuntime().exec(command);
            System.out.println("服务开启成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String transfer(FileInputStream fileInputStream, String filePath, String type, String filename) {
        try {
            Doc2HtmlUtil doc2HtmlUtil = getDoc2HtmlUtilInstance();
            String pdfName = doc2HtmlUtil.file2pdf(fileInputStream,filePath,type,filename);
            System.out.println("文档转换成功");
            return pdfName;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
//    public static void main(String[] args) throws FileNotFoundException {
//        /** 转换功能测试(一) **/
//        OfficeToPdf officeToPdf = new OfficeToPdf();
//        File file = new File("F:/VideoTest/test.docx");
//        FileInputStream fileInputStream = new FileInputStream(file);
//        officeToPdf.transfer(fileInputStream,"F:/VideoTest/","docx");
//    }
}
